﻿$(document).ready(function() {
	leftSlider.onload();
})

var leftSlider = (function() {

	var init = function() {
		layui.use('form', function() {
			var form = layui.form;
			form.render();
		});
	}

	return {
		onload: function() {
			leftSlider.loadZtree();
			init();
			leftSlider.checkClick();
			leftSlider.collectDate();
			leftSlider.collectCheck();
			leftSlider.collectTip();
		},
		collectShow: function() {
			setTimeout(function() {
				layui.use('layer', function() {
					var layer = layui.layer;
					layer.open({
						type: 1,
						skin: 'layui-layer-demo', //样式类名
						closeBtn: 1, //不显示关闭按钮
						anim: 2,
						title: '添加收藏',
						area: ['1100px', '450px'],
						shadeClose: true, //开启遮罩关闭
						content: $('.wxn_collAdd')

					});
				});

			}, 100)
		},
		closeColl: function() {
			layer.closeAll()
		},
		//弹框复选框点击点击事件：
		checkClick: function() {
			$(".wxn_collAdd ul li label").click(function() {
				$(this).toggleClass("active")
			})
		},

		/*收藏弹框数据展示*/
		collectDate: function() {
			var menulist = {
				"menulist": [{
						"Name": "申报纳税",
						"menulist": [{
								"Name": "申报清单",
								"menulist": ""
							},
							{
								"Name": "货物运输业小规模纳税人异地代开增值税专用发票备案信息确认",
								"menulist": ""
							},
							{
								"Name": "申报清单",
								"menulist": ""
							},
							{
								"Name": "税源信息采集",
								"menulist": ""
							},
							{
								"Name": "申报清单",
								"menulist": ""
							},
							{
								"Name": "税源信息采集",
								"menulist": ""
							},
							{
								"Name": "申报清单",
								"menulist": ""
							},
							{
								"Name": "税源信息采集",
								"menulist": ""
							},
							{
								"Name": "申报清单",
								"menulist": ""
							},
							{
								"Name": "税源信息采集",
								"menulist": ""
							},

						]

					},
					{
						"Name": "法律救济",
						"menulist": [{
								"Name": "违法处置",
								"menulist": ""
							},
							{
								"Name": "纳税担保申请",
								"menulist": ""
							}

						]
					}
				]
			};
			var showlist = $("<ul></ul>");
			showall(menulist.menulist, showlist);
			$(".wxl_collSwdj").append(showlist);

			function showall(menu_list, parent) {
				for(var menu in menu_list) {
					if(menu_list[menu].menulist.length > 0) {
						var li = $("<li></li>");
						$(li).append("<label></label><span>" + menu_list[menu].Name + "</span>").append("<ul class='submenu'></ul>").appendTo(parent);
						showall(menu_list[menu].menulist, $(li).children().eq(2));
					} else {
						$("<li></li>").append("<label></label><span>" + menu_list[menu].Name + "</span>").appendTo(parent);
					}
				}
			};
		},
		/*收藏弹框复选框事件*/
		collectCheck: function() {
			$(".wxl_collSwdj").on("click", "label", function() {
				$(this).toggleClass("active");
			});
		},
		/*弹框搜索提示框*/
		collectTip: function() {
			$(".wxl_coll_input").keyup(function() {
				$(".wxl_tip_box ul").empty().show();
				var filter = $(this).val();
				console.log(filter)
				if(filter) {
					$matches = $(".wxl_collSwdj li>.submenu").find("span:Contains(" + filter + ")");
					if($matches.length > 0) {
						for(i = 0; i < $matches.length; i++) {
							var html = "<li>" + $matches[i].innerText + "</li>";
							$(".wxl_tip_box ul").append(html)
						}
					}
				} else {
					$(".wxl_tip_box ul").empty()
				}
				return false;
			});
			$(".wxl_tip_box").on("click", "li", function() {
				var liText = $(this).text();
				$(".wxl_coll_input").val(liText);
				$(".wxl_tip_box ul").empty();
			})
		},

		loadZtree: function() {
			var setting = {
				view: {
					showLine: true,
					selectedMulti: false,
					dblClickExpand: false,
				},
				data: {
					simpleData: {
						enable: true
					}
				},
				callback: {
					beforeExpand: beforeExpand,
					onExpand: onExpand,
					onClick: onClick

				}
			};

			var zNodes = [{
					ID: "01",
					name: "系统功能",
					Url: "",
					open: true,
					children: [

						{
							ID: "1",
							name: "申报缴税",
							Url: "",
							children: [{
									ID: "101",
									name: "增值税（一般纳税人适用）",
									Url: "",
									children: [{
											ID: "10101",
											name: "*增值税纳税申报表（一般纳税人适用）2016版",
											Url: "bsdt/sbqd_v2/sblc_bb.html",
											children: ""
										},
										{
											ID: "10102",
											name: "*增值税纳税申报表附列资料（一）2017版",
											Url: "bsdt/sbqd_v2/sblc_bb.html",
											children: ""
										},
										{
											ID: "10103",
											name: "*增值税纳税申报表附列资料（二）2017版",
											Url: "bsdt/sbqd_v2/sblc_bb.html",
											children: ""
										},
										{
											ID: "10104",
											name: "增值税纳税申报表附列资料（三）2016版",
											Url: "bsdt/sbqd_v2/sblc_bb.html",
											children: ""
										},
										{
											ID: "10105",
											name: "增值税纳税申报表附列资料（四）2016版",
											Url: "bsdt/sbqd_v2/sblc_bb.html",
											children: ""
										},
										{
											ID: "10106",
											name: "增值税纳税申报表附列资料（五）2016版",
											Url: "bsdt/sbqd_v2/sblc_bb.html",
											children: ""
										},
										{
											ID: "10107",
											name: "增值税减免税申报明细表2016版",
											Url: "bsdt/sbqd_v2/sblc_bb.html",
											children: ""
										},
										{
											ID: "10108",
											name: "营改增税负分析测算明细表",
											Url: "bsdt/sbqd_v2/sblc_bb.html",
											children: ""
										},
										{
											ID: "10109",
											name: "代扣代缴税收通用缴款书抵扣清单",
											Url: "bsdt/sbqd_v2/sblc_bb.html",
											children: ""
										},
										{
											ID: "10110",
											name: "汇总纳税企业增值税分配表（2015版）",
											Url: "bsdt/sbqd_v2/sblc_bb.html",
											children: ""
										},
										{
											ID: "10111",
											name: "铁路运输企业分支机构增值税汇总纳税信息传递单",
											Url: "",
											children: ""
										},
										{
											ID: "10112",
											name: "电信企业分支机构增值税情况表",
											Url: "",
											children: ""
										},
										{
											ID: "10113",
											name: "邮政企业分支机构增值税情况表",
											Url: "",
											children: ""
										}
									]
								},
								{
									ID: "102",
									name: "增值税农产品核定抵扣（增值税一般纳税人适用）",
									Url: "",
									children: [{
										ID: "10201",
										name: "农产品核定扣除增值税进项税额计算表（汇总表）",
										Url: "",
										children: ""
									},{
										ID: "10202",
										name: "投入产出法核定农产品增值税进项税额计算表",
										Url: "",
										children: ""
									},{
										ID: "10203",
										name: "成本法核定农产品增值税进项税额计算表",
										Url: "",
										children: ""
									},{
										ID: "10204",
										name: "购进农产品直接销售核定农产品增值税进项税额计算表",
										Url: "",
										children: ""
									},{
										ID: "10205",
										name: "购进农产品用于生产经营且不构成货物实体核定农产品增值税进项税额计算表",
										Url: "",
										children: ""
									}]
								},
								{
									ID: "103",
									name: "附加税申报",
									Url: "",
									children: [{
										ID: "10301",
										name: "*城建税、教育费附加、地方教育附加税（费）申报表",
										Url: "",
										children: ""
									}]
								},
								{
									ID: "104",
									name: "居民企业所得税（据实预缴新）",
									Url: "",
									children: [{
										ID: "10401",
										name: "*A200000企业所得税月（季）度纳税申报表2018年版（A类）",
										Url: "",
										children: ""
									},{
										ID: "10402",
										name: "A201010免税收入、减计收入、所得减免等优惠明细表",
										Url: "",
										children: ""
									},{
										ID: "10403",
										name: "A201020固定资产加速折旧（扣除）优惠明细表",
										Url: "",
										children: ""
									},{
										ID: "10404",
										name: "A201030减免所得税优惠明细表附表",
										Url: "",
										children: ""
									},{
										ID: "10405",
										name: "A202000汇总纳税分支机构所得税分配表",
										Url: "",
										children: ""
									},{
										ID: "10406",
										name: "居民企业参股外国企业信息报告表",
										Url: "",
										children: ""
									},{
										ID: "10407",
										name: "技术成果投资入股企业所得税递延纳税备案表",
										Url: "",
										children: ""
									}]
								},
								{
									ID: "105",
									name: "一般企业财务报表",
									Url: "",
									children: [{
										ID: "10501",
										name: "财务报表（月/季）",
										Url: "",
										children: [{
											ID: "1050101",
											name: "*资产负债表",
											Url: "",
											children: ""
										},{
											ID: "1050102",
											name: "*利润表",
											Url: "",
											children: ""
										},{
											ID: "1050103",
											name: "现金流量表",
											Url: "",
											children: ""
										},{
											ID: "1050104",
											name: "所有者权益变动表",
											Url: "",
											children: ""
										}]
									}]
								},
								{
									ID: "106",
									name: "代扣代缴车船税申报",
									Url: "",
									children: [{
										ID: "10601",
										name: "代扣代缴车船税申报表",
										Url: "bsdt/sbqd_v2/ccssbb.html",
										children: ""
									}]
								},
								{
									ID: "107",
									name: "申报作废",
									Url: "",
									children: ""
								},
								{
									ID: "108",
									name: "申报更正",
									Url: "",
									children: ""
								},
								{
									ID: "109",
									name: "海关稽核",
									Url: "",
									children: ""
								},
								{
									ID: "110",
									name: "申报、实时扣款",
									Url: "bsdt/sbqd_v2/sskk.html",
									children: ""
								},
								{
									ID: "111",
									name: "季中转一般人",
									Url: "",
									children: ""
								}
							]
						},
						{
							ID: "2",
							name: "税源信息采集",
							Url: "",
							children: [{
									ID: "201",
									name: "城镇土地使用税税源信息采集",
									Url: "bsdt/xxcj/cztdsy.html",
									children: ""
								},
								{
									ID: "202",
									name: "房产税税源信息采集",
									Url: "bsdt/xxcj/fcssy.html",
									children: ""
								},
								{
									ID: "203",
									name: "土地增值税项目登记",
									Url: "bsdt/xxcj/tdzzs.html",
									children: ""
								},
								{
									ID: "204",
									name: "车船税税源信息维护",
									Url: "bsdt/xxcj/car_boat.html",
									children: ""
								},
								{
									ID: "205",
									name: "水资源税税源信息采集及变更",
									Url: "bsdt/xxcj/szysy.html",
									children: ""
								},
								{
									ID: "206",
									name: "环境保护税税源信息采集",
									Url: "",
									children: ""
								}
							]
						},
						{
							ID: "3",
							name: "涉税事项办理",
							Url: "",
							children: [{
									ID: "301",
									name: "税务登记",
									Url: "",
									children: [{
											ID: "30101",
											name: "变更登记",
											Url: "",
											children: ""
										},
										{
											ID: "30102",
											name: "停业登记",
											Url: "",
											children: ""
										},
										{
											ID: "30103",
											name: "复业登记",
											Url: "",
											children: ""
										},
										{
											ID: "30104",
											name: "扣缴义务人登记",
											Url: "",
											children: ""
										},
										{
											ID: "30105",
											name: "存款账户账号报告",
											Url: "",
											children: ""
										},
										{
											ID: "30106",
											name: "账务会计制度及核算软件备案报告",
											Url: "",
											children: ""
										},
										{
											ID: "30107",
											name: "文化事业建设费缴费信息报告",
											Url: "",
											children: ""
										},
										{
											ID: "30108",
											name: "汽油、柴油生产企业基本情况登记",
											Url: "",
											children: ""
										},
										{
											ID: "30109",
											name: "证件遗失、损毁管理",
											Url: "",
											children: ""
										},
										{
											ID: "30110",
											name: "货物运输业小规模纳税人异地代开增值税专用发票备案",
											Url: "",
											children: ""
										},
										{
											ID: "30111",
											name: "货物运输业小规模纳税人异地代开增值税专用发票备案信息确认",
											Url: "",
											children: ""
										},
										{
											ID: "30112",
											name: "注销税务登记申请",
											Url: "",
											children: ""
										}
									]
								},
								
								{
									ID: "302",
									name: "认定管理",
									Url: "",
									children: [{
											ID: "30201",
											name: "增值税一般纳税人登记",
											Url: "",
											children: ""
										},
										{
											ID: "30202",
											name: "选择按小规模纳税人纳税",
											Url: "",
											children: ""
										},
										{
											ID: "30203",
											name: "增值税即征即退资格备案",
											Url: "",
											children: ""
										},
										{
											ID: "30204",
											name: "对纳税人变更纳税定额的核准",
											Url: "",
											children: ""
										},
										{
											ID: "30205",
											name: "简并征期申请",
											Url: "",
											children: ""
										},
										{
											ID: "30206",
											name: "简并征期取消",
											Url: "",
											children: ""
										},
										{
											ID: "30207",
											name: "一般纳税人简易方法征收备案",
											Url: "",
											children: ""
										},
										{
											ID: "30208",
											name: "非居民企业选择由其主要机构场所汇总缴纳企业所得税的审批",
											Url: "",
											children: ""
										},
										{
											ID: "30209",
											name: "对采取实际利润额预缴以外的其他企业所得税预缴方式的核定",
											Url: "",
											children: ""
										},
										{
											ID: "30210",
											name: "境外注册中资控股企业居民身份认定申请",
											Url: "",
											children: ""
										},
										{
											ID: "30211",
											name: "企业所得税汇总纳税总分机构信息备案",
											Url: "",
											children: ""
										},
										{
											ID: "30212",
											name: "增值税、消费税汇总纳税认定",
											Url: "",
											children: ""
										}
									]
								},
								{
									ID: "303",
									name: "税收优惠",
									Url: "",
									children: [{
										ID: "30301",
										name: "增值税减免税备案",
										Url: "",
										children: ""
									},{
										ID: "30302",
										name: "消费税减免税备案",
										Url: "",
										children: ""
									},{
										ID: "30303",
										name: "增值税即征即退办理*",
										Url: "",
										children: ""
									},{
										ID: "30304",
										name: "纳税人放弃免（减）税权备案",
										Url: "",
										children: ""
									}]
								},
								{
									ID: "304",
									name: "申报征收",
									Url: "",
									children: [{
										ID: "30401",
										name: "延期申报*",
										Url: "",
										children: ""
									},{
										ID: "30402",
										name: "延期缴纳税款*",
										Url: "",
										children: ""
									},{
										ID: "30403",
										name: "多缴税费退（抵）办理*",
										Url: "",
										children: ""
									},{
										ID: "30404",
										name: "欠税人处置不动产或大额资产报告",
										Url: "",
										children: ""
									},{
										ID: "30405",
										name: "授权（委托）划缴协议",
										Url: "",
										children: ""
									}]
								},
								{
									ID: "305",
									name: "税收证明",
									Url: "",
									children: [{
										ID: "30501",
										name: "丢失增值税专用发票已报税证明单开具",
										Url: "",
										children: ""
									},{
										ID: "30502",
										name: "《中国税收居民身份证明》开具*",
										Url: "",
										children: ""
									},{
										ID: "30503",
										name: "服务贸易等项目对外支付税务备案",
										Url: "",
										children: ""
									},{
										ID: "30504",
										name: "开具税收完税证明（文书式）",
										Url: "",
										children: ""
									}]
								},
								{
									ID: "306",
									name: "跨区域涉税事项",
									Url: "",
									children: [{
										ID: "30601",
										name: "跨区域涉税事项报告",
										Url: "",
										children: ""
									},{
										ID: "30602",
										name: "跨区域涉税事项报验登记缴销",
										Url: "",
										children: ""
									},{
										ID: "30603",
										name: "跨区域涉税事项延期",
										Url: "",
										children: ""
									}]
								},
								{
									ID: "307",
									name: "涉税专业服务",
									Url: "",
									children: [{
										ID: "30701",
										name: "涉税专业服务机构实名信息采集",
										Url: "",
										children: ""
									},{
										ID: "30702",
										name: "涉税专业服务人员信息采集",
										Url: "",
										children: ""
									},{
										ID: "30703",
										name: "涉税专业服务机构人员、证书关系维护",
										Url: "",
										children: ""
									},{
										ID: "30704",
										name: "涉税专业服务机构（人员）实名信息变更",
										Url: "",
										children: ""
									},{
										ID: "30705",
										name: "涉税专业服务协议信息采集",
										Url: "",
										children: ""
									},{
										ID: "30706",
										name: "涉税专业服务协议信息变更及终止",
										Url: "",
										children: ""
									},{
										ID: "30707",
										name: "涉税专项报告信息采集",
										Url: "",
										children: ""
									},{
										ID: "30708",
										name: "涉税专业服务机构年度报告",
										Url: "",
										children: ""
									},{
										ID: "30709",
										name: "涉税专业服务中止",
										Url: "",
										children: ""
									},{
										ID: "30710",
										name: "涉税专业服务恢复",
										Url: "",
										children: ""
									}]
								},
								{
									ID: "308",
									name: "涉税事项查询",
									Url: "",
									children: [{
										ID: "30801",
										name: "涉税事项业务查询",
										Url: "",
										children: ""
									},{
										ID: "30802",
										name: "流转业务查询",
										Url: "",
										children: ""
									},{
										ID: "30803",
										name: "税务通知书查询",
										Url: "",
										children: ""
									}]
								}
							]
						},
						{
							ID: "4",
							name: "发票管理",
							Url: "",
							children: [{
									ID: "401",
									name: "普通发票票种核定及调整",
									Url: "",
									children: ""
								},
								{
									ID: "402",
									name: "印有本单位名称发票核定",
									Url: "",
									children: ""
								},
								{
									ID: "403",
									name: "防伪税控系统发票核定及调整",
									Url: "",
									children: ""
								},
								{
									ID: "404",
									name: "发票领用",
									Url: "",
									children: ""
								},
								{
									ID: "405",
									name: "电子发票领用",
									Url: "",
									children: ""
								},
								{
									ID: "406",
									name: "增值税专用发票代开",
									Url: "",
									children: ""
								},
								{
									ID: "407",
									name: "增值税发票验交旧",
									Url: "",
									children: ""
								},
								{
									ID: "408",
									name: "增值税普通发票代开",
									Url: "",
									children: ""
								},
								{
									ID: "409",
									name: "定额发票验交旧",
									Url: "",
									children: ""
								},
								{
									ID: "410",
									name: "普通发票挂失、损毁报告",
									Url: "",
									children: ""
								},
								{
									ID: "411",
									name: "增值税发票挂失、损毁报备",
									Url: "",
									children: ""
								},
								{
									ID: "412",
									name: "增值税专用发票（增值税税控系统）最高开票限额审批*",
									Url: "",
									children: ""
								},
								{
									ID: "413",
									name: "购票人维护",
									Url: "",
									children: ""
								}
							]
						},

						{
							ID: "5",
							name: "社保费缴纳",
							Url: "",
							children: [{
									ID: "501",
									name: "单位社会保险费日常申报（全责）",
									Url: "",
									children: ""
								},
								{
									ID: "502",
									name: "社会保险费缴纳",
									Url: "",
									children: ""
								}
							]
						},
						{
							ID: "6",
							name: "法律救济",
							Url: "",
							children: [{
									ID: "601",
									name: "违法处置",
									Url: "",
									children: ""
								},
								{
									ID: "602",
									name: "纳税担保申请",
									Url: "",
									children: ""
								}

							]
						}
					]
				},
				{
					ID: "02",
					name: "个性服务",
					Url: "",
					children: [{
							ID: "7",
							name: "涉税事项套餐",
							Url: "",
							children: [{
									ID: "701",
									name: "新办那税人套餐服务",
									Url: "",
									children: ""
								},
								{
									ID: "702",
									name: "专题套餐服务",
									Url: "",
									children: ""
								},
								{
									ID: "702",
									name: "自定义套餐服务",
									Url: "",
									children: ""
								}
							]
						},
						{
							ID: "8",
							name: "银税互动",
							Url: "",
							children: [{
									ID: "801",
									name: "我的贷款",
									Url: "",
									children: ""
								},
								{
									ID: "802",
									name: "我的申请",
									Url: "",
									children: ""
								}
							]
						},
						{
							ID: "9",
							name: "涉税风险自查",
							Url: "",
							children: [{
									ID: "901",
									name: "涉税风险自查",
									Url: "",
									children: ""
								}
							]
						}

					]
				}
			]

			var curExpandNode = null;

			function beforeExpand(treeId, treeNode) {
				var pNode = curExpandNode ? curExpandNode.getParentNode() : null;
				var treeNodeP = treeNode.parentTId ? treeNode.getParentNode() : null;
				var zTree = $.fn.zTree.getZTreeObj("sidebarZtr");
				for(var i = 0, l = !treeNodeP ? 0 : treeNodeP.children.length; i < l; i++) {
					if(treeNode !== treeNodeP.children[i]) {
						zTree.expandNode(treeNodeP.children[i], false);
					}
				}
				while(pNode) {
					if(pNode === treeNode) {
						break;
					}
					pNode = pNode.getParentNode();
				}
				if(!pNode) {
					singlePath(treeNode);
				}

			}

			function singlePath(newNode) {
				if(newNode === curExpandNode) return;

				var zTree = $.fn.zTree.getZTreeObj("sidebarZtr"),
					rootNodes, tmpRoot, tmpTId, i, j, n;

				if(!curExpandNode) {
					tmpRoot = newNode;
					while(tmpRoot) {
						tmpTId = tmpRoot.tId;
						tmpRoot = tmpRoot.getParentNode();
					}
					rootNodes = zTree.getNodes();
					for(i = 0, j = rootNodes.length; i < j; i++) {
						n = rootNodes[i];
						if(n.tId != tmpTId) {
							zTree.expandNode(n, false);
						}
					}
				} else if(curExpandNode && curExpandNode.open) {
					if(newNode.parentTId === curExpandNode.parentTId) {
						zTree.expandNode(curExpandNode, false);
					} else {
						var newParents = [];
						while(newNode) {
							newNode = newNode.getParentNode();
							if(newNode === curExpandNode) {
								newParents = null;
								break;
							} else if(newNode) {
								newParents.push(newNode);
							}
						}
						if(newParents != null) {
							var oldNode = curExpandNode;
							var oldParents = [];
							while(oldNode) {
								oldNode = oldNode.getParentNode();
								if(oldNode) {
									oldParents.push(oldNode);
								}
							}
							if(newParents.length > 0) {
								zTree.expandNode(oldParents[Math.abs(oldParents.length - newParents.length) - 1], false);
							} else {
								zTree.expandNode(oldParents[oldParents.length - 1], false);
							}
						}
					}
				}
				curExpandNode = newNode;
			}

			function onExpand(event, treeId, treeNode) {
				// 修复背景不平铺
		    $("#sidebarZtr").css("display","table");

				curExpandNode = treeNode;
			}

			function onClick(e, treeId, treeNode) {
				var zTree = $.fn.zTree.getZTreeObj("sidebarZtr"); // zTree 对象
				zTree.expandNode(treeNode, null, null, null, true);
				// console.log(e.parent().css('width'));
				// console.log($('.slidebar_nav').css('width',$('.slidebar_nav').parent().outerWidth(true)));//只有一个值
				// console.log($(this).parents('.slidebar_nav').outerWidth());
				console.log(e); //e是事件
				console.log(treeNode.ID);
				console.log(treeNode.Url);
				console.log(treeNode.name);
				slider.tabIframe(treeNode.name, treeNode.Url, treeNode.ID)
			}

			$(document).ready(function() {
				$.fn.zTree.init($("#sidebarZtr"), setting, zNodes);
			});
		}
	}
})();